package com.jack.payment.util.common;


import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.math.BigDecimal;

@Component
public class BigDecimalUtil {
    private Logger log = LoggerFactory.getLogger(BigDecimalUtil.class);

    public  static final BigDecimal ZERO = new BigDecimal("0.00");

    public static final BigDecimal HOUDRED = new BigDecimal("100");

    /**  BigDecimal 乘法进位处理  如 2.355, 进位后位3.36, 遇5进1 **/
    public static BigDecimal multiplyRoundUp(BigDecimal bigDecimal1, BigDecimal bigDecimal2) {
        return bigDecimal1.multiply(bigDecimal2).setScale(2, BigDecimal.ROUND_HALF_UP);
    }
    /**  BigDecimal 乘法进位处理  如 2.355, 进位后位3.36, 遇5进1 **/
    public static BigDecimal devideRoundUp(BigDecimal bigDecimal1, BigDecimal bigDecimal2) {
        return bigDecimal1.divide(bigDecimal2, BigDecimal.ROUND_HALF_UP);
    }

    /** BigDecimal 比较大小  -1:小于 0:等于 1:大于 **/
    public static int commpareTo(BigDecimal bigDecimal1, BigDecimal bigDecimal2) {
        return  bigDecimal1.compareTo(bigDecimal2);
    }

    /** BigDecimal 加减 如 2.355, 进位后位3.36, 遇5进1 **/
    public static BigDecimal addRoundUp(BigDecimal bigDecimal1, BigDecimal bigDecimal2) {
        return bigDecimal1.add(bigDecimal2).setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    /** BigDecimal 加减 如 2.355, 进位后位3.36, 遇5进1 **/
    public static BigDecimal subtractRoundUp(BigDecimal bigDecimal1, BigDecimal bigDecimal2) {
        return bigDecimal1.subtract(bigDecimal2).setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    /** stripe 支付 需乘100  **/
    public static BigDecimal mulipyBigDeimalHoured(BigDecimal payAmount) {
        return payAmount.multiply(HOUDRED).setScale(2, BigDecimal.ROUND_HALF_UP);
    }

    /** stripe 支付成功后需除100 得到正常数值的货币 **/
    public static BigDecimal divideBigDeimalHoured(Long payAmount) {
        BigDecimal actualAmount = new BigDecimal(payAmount);
        return actualAmount.divide(HOUDRED).setScale(2, BigDecimal.ROUND_HALF_UP);
    }



}
